package com.guoxin.chapter2.throwexceptionnolock;

/**
 * 出现异常的锁被自动释放了
 * 
 * @author Administrator
 *
 */
public class Service {
	public synchronized void testMethod() {
		if ("a".equals(Thread.currentThread().getName())) {
			System.out.println("Thread.currentThread().getName()=" + Thread.currentThread().getName()
					+ " run beginTime=" + System.currentTimeMillis());
			int i = 1;
			while (i == 1) {
				if ("0.123456".equals(("" + Math.random()).substring(0, 8))) {
					System.out.println("ThreadName=" + Thread.currentThread().getName() + " run exceptionTime="
							+ System.currentTimeMillis());
					Integer.parseInt("a");
				}
			}
		} else {
			System.out.println("Thread B run Time=" + System.currentTimeMillis());
		}
	}
}
